package org.theSeed.utils;

import cn.hutool.core.util.ObjectUtil;
import org.theSeed.pojo.dto.UserInfo;
import org.theSeed.pojo.dto.UserInfoUserDetails;
import org.theSeed.rbacBaseCommon.pojo.constant.RbacConstant;

/**
 * 登录工具
 */
public class LoginHelper {
    /**
     * 获取登录信息
     * @return
     */
    public static UserInfoUserDetails getLoginInfo(){
        return (UserInfoUserDetails)(ThreadCacheUtil.getThreadCache(RbacConstant.LOGIN_THREAD_CACHE).getData());
    }

    /**
     * 获取用户基础信息
     * @return
     */
    public static UserInfo getUserInfo(){
        return ObjectUtil.isNotNull(getUserInfo()) ?getLoginInfo().getUserInfo():null;
    }

    /**
     * 获取用户标识
     * @return
     */
    public static String getUserKey(){
        return ObjectUtil.isNotNull(getUserInfo()) ?getLoginInfo().getUserKey():null;
    }

    /**
     * 设置登录用户信息线程缓存
     */
    public static void setLoginInfo(UserInfoUserDetails userInfo){
        ThreadCacheUtil.getThreadCache(RbacConstant.LOGIN_THREAD_CACHE).setData(userInfo);
    }
}
